<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-content">
        <div class="login-header">
          <img src="https://cdn-icons-png.flaticon.com/512/2232/2232688.png" alt="logo" class="logo">
          <h2>大学生学习预警系统</h2>
          <p class="subtitle">欢迎使用学习预警管理平台</p>
        </div>
        <form class="login-form" @submit.prevent>
          <div class="form-group">
            <el-input
              v-model="teacher.ttid"
              placeholder="请输入用户名"
              prefix-icon="User"
            />
          </div>
          <div class="form-group">
            <el-input
              v-model="teacher.tpassword"
              type="password"
              placeholder="请输入密码"
              prefix-icon="Lock"
              show-password
            />
          </div>
          <div class="form-group">
            <el-button type="primary" class="login-button" @click="teacherLogin">
              登录
            </el-button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from 'vue';
import { useRouter } from "vue-router";
import axios from 'axios';
import {setSessionStorage} from '../router/common';
import websocketService from '../utils/websocket';

export default {
    setup() {
      const router = useRouter();
        const state = reactive({
            teacher:{
              ttid:'202213008393',
              tpassword:'123456',
            }
        })
        function teacherLogin(){
          axios.post('api/teacher/teacher/login',{
            tPassword:state.teacher.tpassword,
            tTid:state.teacher.ttid
          }).then(res=>{
            const result = res.data;
            console.log(result)
            if(result.code == 1){
              setSessionStorage('token',result.data.token);
              setSessionStorage('teacher',result.data.tteacher);
              websocketService.connect();
              router.push('/student');
              alert('登录成功');
            }else{
              alert(result.msg);
            }
          })
        }
        return {
            ...toRefs(state),
            teacherLogin
        }
      }
    }
</script>

<style scoped>
.login-container {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  padding: 20px;
  overflow: hidden;
}

.login-box {
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  animation: fadeIn 0.5s ease-out;
}

.login-content {
  padding: 40px;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo {
  width: 80px;
  height: 80px;
  margin-bottom: 16px;
  animation: bounce 1s ease-in-out;
}

.login-header h2 {
  color: #2c3e50;
  font-size: 24px;
  margin: 0 0 8px;
}

.subtitle {
  color: #7f8c8d;
  font-size: 14px;
  margin: 0;
}

.login-form {
  margin-top: 30px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.login-button {
  width: 100%;
  height: 40px;
  font-size: 16px;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  border: none;
  transition: transform 0.3s ease;
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(17, 153, 142, 0.3);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0% {
    transform: translateY(-20px);
    opacity: 0;
  }
  50% {
    transform: translateY(10px);
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 响应式设计 */
@media (max-width: 480px) {
  .login-box {
    margin: 20px;
  }
  
  .login-content {
    padding: 30px 20px;
  }
  
  .login-header h2 {
    font-size: 20px;
  }
}
</style>